from graphics import *
import time

def drawCoin(win, x, y):
    coin = Oval(Point(x, y), Point(x+25, y+10))
    coin.setFill('yellow')
    coin.draw(win)

    blacksquare = Rectangle(Point(x+11, y+4), Point(x+13, y+6))
    blacksquare.setFill('black')
    blacksquare.draw(win)

def drawFrog(win, x, y):

    # This is the Left Foot
    p1 = Point(x+25, y+85)
    p2 = Point(x+10, y+100)
    p3 = Point(x+40, y+100)
    foot1 = Polygon(p1, p2, p3)
    foot1.setFill('green')
    foot1.draw(win)

    # Right Foot
    p4 = Point(x+75, y+85)
    p5 = Point(x+60, y+100)
    p6 = Point(x+90, y+100)
    foot2 = Polygon(p4, p5, p6)
    foot2.setFill('green')
    foot2.draw(win)

    frog = Oval(Point(x,y), Point(x+100, y+100))
    frog.setFill('green')
    frog.draw(win)    

    # Left Eye
    eye1 = Oval(Point(x, y), Point(x+25, y+25))
    eye1.setFill('white')
    eye1.draw(win)

    # Right Eye
    eye2 = Oval(Point(x+75, y), Point(x+100, y+25))
    eye2.setFill('white')
    eye2.draw(win)

    # Left Pupil
    pupil1 = Circle(Point(x+12, y+12), 4)
    pupil1.setFill('black')
    pupil1.draw(win)

    # Right Pupil
    pupil2 = Circle(Point(x+75+12, y+12), 4)
    pupil2.setFill('black')
    pupil2.draw(win)

    # The mouth
    line1 = Line(Point(x+12, y+50), Point(x+25, y+60)); line1.draw(win)
    line2 = Line(Point(x+25, y+60), Point(x+75, y+60)); line2.draw(win)
    line3 = Line(Point(x+75, y+60), Point(x+87, y+50)); line3.draw(win)

def drawFly(win, x, y):
    flyBody = Rectangle(Point(x,y), Point(x+20, y+4))
    flyBody.setFill('white')
    flyBody.draw(win)

    flyWing = Oval(Point(x+4,y-20), Point(x+8, y))
    flyWing.setFill('white')
    flyWing.draw(win)

    for i in range(3):
        # Move up and to the left
        for j in range(50):
            time.sleep(0.05)
            flyBody.move(-1,-1)
            flyWing.move(-1,-1)
        # Move down and to the left
        for j in range(50):
            time.sleep(0.05)
            flyBody.move(-1,1)
            flyWing.move(-1,1)

    return (flyBody, flyWing)

def drawTongue(win, x, y, flyBody, flyWing):
    p1 = flyBody.getP1()
    p2 = Point(p1.getX()+5, p1.getY())
    p3 = Point(x+70, y+60)
    p4 = Point(x+75, y+60)
    tongue = Polygon(p1,p2,p3,p4)
    tongue.setFill('red')
    tongue.draw(win)

    time.sleep(1)

    tongue.undraw()
    flyBody.undraw()
    flyWing.undraw()
    time.sleep(2.0)

def drawPond(win):
    sky = Rectangle(Point(0,0), Point(399, 249)) 
    sky.setFill( color_rgb(0, 0, 255) )
    sky.draw(win)

    water = Rectangle(Point(0, 250), Point(399, 399))
    water.setFill( color_rgb(0, 0, 128) )
    water.draw(win)

    # Draw 20 gold coins for the frog's lily pad
    y = 5
    while y > 0: 
        x = 0
        while x < 4:
            drawCoin(win, 25 + 25 * x, 300 + 10 * y)
            x += 1
        y -= 1

    # And the frog...
    drawFrog(win, 25, 200)

    speechBubble = Oval(Point(175, 200), Point(375, 300))
    speechBubble.setFill('white')
    speechBubble.draw(win)

    message = Text(Point(275, 250), "Hi")
    message.draw(win)
    time.sleep(2.0)

    message.setText("I'm a frog."); time.sleep(2.0)
    message.setText("Could you tell?"); time.sleep(2.0)
    message.setText("My lily pad is gold coins!"); time.sleep(2.0)
    message.setText("Anyway, I'm also a lazy frog."); time.sleep(2.0)
    message.setText("I hope a fly comes by."); time.sleep(2.0)
    message.setText("Here comes one now."); time.sleep(2.0)

    message.undraw()
    speechBubble.undraw()

    (flyBody, flyWing) = drawFly(win, 400, 100)

    # Now to animate the tounge!
    drawTongue(win, 25, 200, flyBody, flyWing)

    speechBubble.draw(win)
    message.draw(win)
    message.setText("Yum! Good!")

def main():
    win = GraphWin("My Frog Pond", 400, 400)
    drawPond(win)
    win.getMouse()
    win.close()

main()
